<template>
  <el-container>
    <el-aside width="200px"></el-aside>
    <el-main>
      <div class="d1">
        <h1>同城管理系统</h1>
        <el-form :model="form" :rules="rules" label-width="auto" style="max-width: 300px;margin:0 auto;">
          <el-form-item label="用户名" prop="account">
            <el-input v-model="form.account" />
          </el-form-item>
          <el-form-item label="密码" prop="password">
            <el-input v-model="form.password" show-password type="password"/>
          </el-form-item>
          <el-form-item>
            <span class="ss" @click="dl">登录</span>
          </el-form-item>
        </el-form>
      </div>
    </el-main>
  </el-container>
</template>

<script>
import {login} from "@/api/vue3.js";
import {ElMessage} from "element-plus";
export default {
  name: 'Login',
  data(){
    return {
      form: {
        account: '',
        password: '',
      },
      rules: {
        account: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 3, max: 6, message: '长度在 3 到 6 个字符', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    dl() {
      if (this.form.account == '' || this.form.password == '') {
        ElMessage({
          message: '请输入账号密码',
          type: 'error',
        })
      } else {
        login(this.form).then(res => {
          console.log(res)
          if (res.data.data.code == 222) {
            ElMessage({
              message: '登录成功',
              type: 'success',
            })
            localStorage.setItem('token', res.data.data.token)
            localStorage.setItem('manager', res.data.data.data.manager)
            localStorage.setItem('headUrl', res.data.data.data.headUrl)
            console.log(localStorage.getItem('manager'))
            this.$router.push('/home')
          } else {
            ElMessage({
              message: res.data.data.msg,
              type: 'error',
            })
          }
        })
      }
    }
  }
}
</script>

<style scoped>
.el-container {
  width: 100%;
  height: 100%;
}
.el-aside{
  width: 60%;
  height: 100%;
  background: url("@/views/login/img/back1.jpg") no-repeat;
  background-size: contain;
}
img{
  margin-left: 100px;
}
.d1{
  width: 450px;
  height: 400px;
  margin-top: 35%;
  border-radius: 30px;
  box-shadow: 1px 1px 8px #bfb6b7;
}
h1{
  text-align: center;
  line-height: 150px;
  font-size: 30px;
  color:black;
  margin-bottom: 10px;
}
.ss{
  width: 160px;
  height: 35px;
  background-color: #089DAD;
  color: white;
  font-size: 17px;
  line-height: 35px;
  border-radius: 5px;
  text-align: center;
  margin:0 auto;
}
</style>